console.log(params);


var myChart = params.getEchartsItem();

option = {
    title: {
        text: 'Step Line'
    },
    tooltip: {
        trigger: 'axis'
    },
    legend: {
        data: ['Step Start', 'Step Middle', 'Step End']
    },
    grid: {
        left: '3%',
        right: '4%',
        bottom: '3%',
        containLabel: true
    },
    toolbox: {
        feature: {
            saveAsImage: {}
        }
    },
    xAxis: {
        type: 'category',
        data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
    },
    yAxis: {
        type: 'value'
    },
    series: [
        {
            name: 'Step Start',
            type: 'line',
            step: 'start',
            data: [120, 132, 101, 134, 90, 230, 210]
        },
        {
            name: 'Step Middle',
            type: 'line',
            step: 'middle',
            data: [220, 282, 201, 234, 290, 430, 410]
        },
        {
            name: 'Step End',
            type: 'line',
            step: 'end',
            data: [450, 432, 401, 454, 590, 530, 510]
        }
    ]
};

// 我们希望以杯型做堆叠，schema[1]是杯型
option.legend.data = params.data.schema[1].dataUniq;
// 我们希望y轴是咖啡类型，schema[0]是咖啡类型
option.xAxis.data = params.data.schema[0].dataUniq;
// 初始化用legend数据初始化series
// 用yAxis初始化series中每一个data, 用空值初始化目的是在缺失数据时可以保留空数据
option.series = params.data.schema[1].dataUniq.map(n => ({
            name: n,
            type: 'line',
            step: 'middle',
            data: params.data.schema[0].dataUniq.map(x => 0)
        }));
var firstDim = params.data.schema[0].dataUniq.reduce((dict, val, i) => { dict[val] = i; return dict;}, {});
var secondDim = params.data.schema[1].dataUniq.reduce((dict, val, i) => { dict[val] = i; return dict;}, {});
for (var i = 0; i < params.data.schema[2].data.length; i++) {
    firstIndex = firstDim[params.data.schema[0].data[i]];
    secondIndex = secondDim[params.data.schema[1].data[i]];
    option.series[secondIndex].data[firstIndex] = params.data.schema[2].data[i];
}




myChart.setOption(option);



myChart.on('click', function (option) {
  params.onHSClickHandler([{
    data: option.name === 'null' ? null : option.name,
    path: 0,
  }])
});














